package com.ushio.gougouwangguo.controller;

import com.ushio.commonmodule.pojo.result.Result;
import com.ushio.gougouwangguo.entity.mysql.ActionConfig;
import com.ushio.gougouwangguo.entity.qo.ActionConfigQo;
import com.ushio.gougouwangguo.entity.qo.ActionConfigUpdataQo;
import com.ushio.gougouwangguo.entity.vo.ActionConfigVo;
import com.ushio.gougouwangguo.service.IActionConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 张文凯
 * @since 2025-09-22
 */
@RestController
@RequestMapping("/actionConfig")
@Tag(name = "ActionConfig", description = "操作配置")
public class ActionConfigController {

    @Autowired
    IActionConfigService iActionConfigService;

    @PostMapping
    @Operation(summary = "查询操作需要属性",description = "查询操作需要属性")
    private Result<List<ActionConfigVo>> getActionConfig(@RequestBody ActionConfigQo actionConfigQo){
        try{

            List<ActionConfigVo> actionConfig = iActionConfigService.getActionConfig(actionConfigQo);

            return Result.success(actionConfig);

        }catch (Exception e){

            e.printStackTrace();

             return  Result.fail(e.getMessage());

        }
    }

    @PostMapping("/role_occupation")
    @Operation(summary = "角色占用",description = "查询角色是否占用,如果占用,将不能使用该角色")
    private Result<List<ActionConfigVo>> getroleOccupation(@RequestBody ActionConfigQo actionConfigQo){
        try{

            List<ActionConfigVo> actionConfig = iActionConfigService.getroleOccupation(actionConfigQo);

            return Result.success(actionConfig);

        }catch (Exception e){

            e.printStackTrace();

            return  Result.fail(e.getMessage());

        }
    }

    @GetMapping()
    @Operation(summary = "查询配置列表",description = "配置任务")
    private Result<List<ActionConfigVo>> getActionConfigTable(){
        try{

            List<ActionConfigVo> actionConfig = iActionConfigService.getActionConfigTable();

            return Result.success(actionConfig);

        }catch (Exception e){

            e.printStackTrace();

            return  Result.fail(e.getMessage());

        }
    }

    @PostMapping("/updata")
    @Operation(summary = "查询配置列表",description = "配置任务")
    private Result<List<ActionConfigVo>> upDataActionConfigTable(@RequestBody ActionConfigUpdataQo actionConfigUpdataQo){
        try{

             iActionConfigService.upDataActionConfigTable(actionConfigUpdataQo);

            return Result.success();

        }catch (Exception e){

            e.printStackTrace();

            return  Result.fail(e.getMessage());

        }
    }

    @PostMapping("/delete")
    @Operation(summary = "查询配置列表",description = "配置任务")
    private Result<List<ActionConfigVo>> deleteActionConfigTable(@RequestBody ActionConfigUpdataQo actionConfigUpdataQo){
        try{

            iActionConfigService.deleteActionConfigTable(actionConfigUpdataQo);

            return Result.success();

        }catch (Exception e){

            e.printStackTrace();

            return  Result.fail(e.getMessage());

        }
    }

}
